layui.use(['carousel', 'form'], function(){
    var carousel = layui.carousel
    ,form = layui.form;
    
    //常规轮播
    carousel.render({
      elem: '#test1'
    });
    
    //改变下时间间隔、动画类型、高度
    carousel.render({
      elem: '#test2'
      ,interval: 1800
      ,anim: 'fade'
      ,height: '120px'
    });
    
    //设定各种参数
    var ins3 = carousel.render({
      elem: '#test3'
    });
    //图片轮播
    carousel.render({
      elem: '#test10'
      ,width: '1903px'
      ,height: '550px'
      ,interval: 3000
      
    });
    
    //事件
    carousel.on('change(test4)', function(res){
      console.log(res)
    });
    
    var $ = layui.$, active = {
      set: function(othis){
        var THIS = 'layui-bg-normal'
        ,key = othis.data('key')
        ,options = {};
        
        othis.css('background-color', '#5FB878').siblings().removeAttr('style'); 
        options[key] = othis.data('value');
        ins3.reload(options);
      }
    };
    
    //开关事件
    form.on('switch(autoplay)', function(){
      ins3.reload({
        autoplay: this.checked
      });
    });
    // 自动播放控制
    form.on('select(autoplay)', function (obj) {
      // debugger;
      var autoplayValue = parseInt(obj.value);
      ins3.reload({
        autoplay: isNaN(autoplayValue) ? obj.value : autoplayValue
      });
    })
    
    $('.demoSet').on('keyup', function(){
      var value = this.value
      ,options = {};
      if(!/^\d+$/.test(value)) return;
      
      options[this.name] = value;
      ins3.reload(options);
    });
    
    //其它示例
    $('.demoTest .layui-btn').on('click', function(){
      var othis = $(this), type = othis.data('type');
      active[type] ? active[type].call(this, othis) : '';
    });
  });